package com.ambulance.project.biz.controller.common;

import com.ambulance.common.exception.CustomException;
import com.ambulance.framework.web.domain.AjaxResult;
import com.ambulance.project.manager.domain.BizDoctor;
import com.ambulance.project.manager.domain.BizHospital;
import com.ambulance.project.manager.domain.HospitalDoctorDto;
import com.ambulance.project.manager.service.IBizDoctorService;
import com.ambulance.project.manager.service.IBizHospitalService;
import com.ambulance.utils.CommonUtils;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author RXL
 * @Date 2020/6/28 12:26
 * @Version 1.0
 */
@Api(tags = "多端共用-查询房间信息")
@RestController
@RequestMapping(value = "/common/v1/channel", method = RequestMethod.POST)
public class VideoUserController {

    @Autowired
    private IBizDoctorService iBizDoctorService;
    @Autowired
    private IBizHospitalService iBizHospitalService;

    @ApiOperation(value = "频道信息", notes = "频道信息", produces = "application/json")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "房间号", required = true, dataType = "int"),
    })
    @ApiResponses({
            @ApiResponse(code = 200, response = HospitalDoctorDto.class, message = "响应")
    })
    @RequestMapping(value = "info")
    public AjaxResult info(@RequestParam(value = "id") Integer id) {
        final HospitalDoctorDto hospitalDoctorDto = new HospitalDoctorDto();
        if (id < 10000000) {
            //todo 查医生
            final BizDoctor bizDoctor = iBizDoctorService.selectBizDoctorById(id.longValue());
            if (CommonUtils.checkNull(bizDoctor)) {
                throw new CustomException("房间号错误");
            }
            hospitalDoctorDto.setUid(bizDoctor.getUid().toString());
            hospitalDoctorDto.setType("3");
            hospitalDoctorDto.setDepart(bizDoctor.getDepart());
            hospitalDoctorDto.setName(bizDoctor.getName());
            hospitalDoctorDto.setCommonID(bizDoctor.getDoctorID().toString());
            hospitalDoctorDto.setHospital(bizDoctor.getHospital());
        } else {
            //查医院和科室
            final BizHospital bizHospital = iBizHospitalService.selectBizHospitalById(id.longValue());
            if (CommonUtils.checkNull(bizHospital)) {
                throw new CustomException("房间号错误");
            }
            hospitalDoctorDto.setUid(bizHospital.getUid().toString());
            hospitalDoctorDto.setType(bizHospital.getType().toString());
            hospitalDoctorDto.setDepart(bizHospital.getDepart());
            hospitalDoctorDto.setName(bizHospital.getHospitalName());
            hospitalDoctorDto.setCommonID(bizHospital.getHospitalID().toString());
            hospitalDoctorDto.setHospital(bizHospital.getHospitalName());
        }
        return AjaxResult.success(hospitalDoctorDto);
    }
}
